package com.htdata.service;

import com.casic.iot.client.IotAcquireClient;
import com.casic.iot.model.request.IotAcquireRequest;
import com.casic.iot.model.response.IotAcquireResponse;
import java.lang.Thread;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by T数据部 on 2017/5/26.
 */
public class DevData2Cloud extends Thread {
    private  Map config =new HashMap();
    String url ="http://iotapi.casicloud.com/api/1.1/iot/data_acquire";
    long ts = System.currentTimeMillis();
    //create data
    long value =(long)(Math.random()*100+500);

    public DevData2Cloud(Map config){
        this.config=config;
    }

    public void run() {
        IotAcquireClient client = new IotAcquireClient(url, (String) config.get("accesskey"));
        IotAcquireRequest req = new IotAcquireRequest();
        req.setIot((String) config.get("iot"));
        req.setEquipment((String) config.get("eq"));
        while(true) {
            req.addData("tem",value, ts);//设置采集点数据
            IotAcquireResponse result = client.execute(req);

            System.out.println("putin dev data success");
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(df.format(new Date()));// new Date()为获取当前系统时间

            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        }

    }
